{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 中级组赛事手动demo"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import rospy   #ROS\n",
    "import cv2     #机器视觉库\n",
    "from aikit_lib import aikit_2wd #AIKIT库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "aikit=aikit_2wd.robot()   #实例化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "old_k=0\n",
    "while True:\n",
    "    frame=aikit.read_camera()\n",
    "    cv2.imshow('cv2',frame)\n",
    "    \n",
    "    k = cv2.waitKey(1) & 0xFF\n",
    "    if k!=old_k:\n",
    "        print(k)\n",
    "    old_k = k\n",
    "    if k == 27:\n",
    "        break\n",
    "    elif k == ord('i'):\n",
    "        print(\"前进\")\n",
    "    elif k == ord('m'):\n",
    "        print(\"后退\")\n",
    "    elif k == ord('k'):\n",
    "        print(\"停止\")                            \n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bottle=0\n",
    "orange=0\n",
    "greenorange=0\n",
    "while True:\n",
    "    frame=aikit.read_camera()\n",
    "    cv2.imshow('res',frame)\n",
    "    \n",
    "    k = cv2.waitKey(1) & 0xFF\n",
    "    if k == 27: #ESC退出\n",
    "        break\n",
    "    elif k == ord('i'):\n",
    "        print(\"前进\")\n",
    "        aikit.go(0.3,1)     \n",
    "    elif k == ord('m'):\n",
    "        print(\"后退\")\n",
    "        aikit.go(-0.3,1)  \n",
    "    elif k == ord('j'):\n",
    "        print(\"左转\")\n",
    "        aikit.turn(0.3,1) \n",
    "    elif k == ord('l'):\n",
    "        print(\"右转\")\n",
    "        aikit.turn(-0.3,1) \n",
    "    elif k == ord('k'):\n",
    "        print(\"停止\")  \n",
    "        aikit.go(0,1)  \n",
    "    elif k == ord('1'):\n",
    "        print(\"爪子张开\")\n",
    "        aikit.set_claw(90)\n",
    "    elif k == ord('2'):\n",
    "        print(\"爪子闭合\")\n",
    "        aikit.set_claw(50)\n",
    "    elif k == ord('3'):\n",
    "        print(\"shibie\")        \n",
    "        label=aikit.object_label()\n",
    "        if(label=='bottle'):\n",
    "            bottle+=1\n",
    "            aikit.play_sound(\"瓶子\")\n",
    "        elif(label=='orange'):\n",
    "            orange+=1\n",
    "        elif(label=='greenorange'):\n",
    "            greenorange+=1\n",
    "    elif k == ord('a'):\n",
    "        aikit.play_sound(\"瓶子\")\n",
    "        aikit.play_sound(str(bottle))\n",
    "        \n",
    "        \n",
    "            \n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
